<?php
require_once("db_connect.php");

$client_id = $_POST['client_id'];

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/jpg"))
&& ($_FILES["file"]["size"] < 1000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    //echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    //echo "Type: " . $_FILES["file"]["type"] . "<br />";
    //echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    //echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

		if(!is_dir('../uploads/logos/'.$client_id))
		  mkdir('../uploads/logos/'.$client_id);
		  
      move_uploaded_file($_FILES["file"]["tmp_name"],"../uploads/logos/".$client_id."/" . $_FILES["file"]["name"]);
	  $filename = $_FILES["file"]["name"];
	  if(mysql_query("UPDATE corporate_clients SET logo='$filename'"))
	   echo '<script>window.location="javascript:history.go(-1)";</script>';
	   else
	   echo mysql_error();
	  
      
    }
  }
else
  {
  echo "Invalid file<br/>";
  echo '<a href="javascript: history.go(-1)">Click here to go back</a>';
  }

?> 